package utils;

import cn.hutool.extra.ftp.Ftp;
import org.apache.commons.net.ftp.FTPFile;

import java.io.IOException;
import java.io.OutputStream;

public class HutoolFtpUtil {

    private Ftp ftp;

    public Ftp getFtp() {
        return ftp;
    }

    public void setFtp(Ftp ftp) {
        this.ftp = ftp;
    }

    public HutoolFtpUtil() {
        ftp = new Ftp("121.36.83.224", 21, "wondertek", "Abc1234%");
    }

    public String pwd() {
        return ftp.pwd();
    }

    public FTPFile[] lsFiles() {
        return ftp.lsFiles("/N8500_35T/XML1");
    }

    public void retrieveFile(String fileName, OutputStream out) throws IOException {
        ftp.getClient().enterLocalPassiveMode();
        ftp.getClient().retrieveFile(fileName, out);
    }

    public static void main(String[] args) {
        HutoolFtpUtil ftpUtil = new HutoolFtpUtil();
        System.out.println("ftpUtil.pwd() = " + ftpUtil.pwd());
        FTPFile[] files = ftpUtil.lsFiles();
        for (FTPFile file : files) {
            System.out.println("file = " + file);
        }

//        String filePath = "/N8500_35T/Program/dysj/2020/11/01/AnHuiFinance_1500000_20201101_235619000_0_72.mp4";
//        String path = filePath.substring(0, filePath.lastIndexOf("/"));
//        String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
//        System.out.println("path = " + path);
//        System.out.println("fileName = " + fileName);
    }

}
